#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
  pid_t id=fork();
  if(id==0)
  {
    int cnt=5;
    while(cnt--)
    {
      printf("我是子进程.......%d\n",getpid());
      sleep(1);
    }
    exit(13);
  }
  else 
  {
    int status =0;
    printf("我是父进程，pid:%d ...我准备等待子进程了\n",getpid());
    pid_t ret =waitpid(id,&status,0);
    if(ret>0)
    {
    if(WIFEXITED(status))
    {

    printf("wait success ,ret : %d ,我所等待的子进程退出码 : %d\n",ret,WEXITSTATUS(status));
    //printf("wait success ,ret : %d ,我所等待的子进程退出码 : %d,退出信号是%d\n",ret,(status>>8)&0xFF,(status)&0x7F);
    }
    }
  }


  return 0;
}
